<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <parent></parent>
  </div>
  <template id="parent">
    <div style="background-color: darkgrey;width: 300px;height: 150px;">
      <child>
        <!-- 在这里接收数据，在插槽的root元素下接收数据，接受的数据是一个json对象的形式 -->
        <header style="background-color: rgb(138, 129, 0);" slot="header" slot-scope="data">
          我是header
          <ul>
            <li v-for="item in data.arr" v-bind:key="item">{{item}}</li>
          </ul>
          {{data.obj}}
        </header>
        <footer style="background-color: darkturquoise;" slot="footer">我是footer</footer>
      </child>
    </div>
  </template>

  <template id="child">
    <div>
      <div style="background-color: darkorange;">我是body</div>
      <!-- 作用域插槽，子组件在slot中发送data中的数据-->
      <slot name="header" :arr="arr" :obj="obj"></slot>
      <slot name="footer"></slot>
    </div>
  </template>
  <script src="../vue.js"></script>
  <script>
    const child = {
      template: '#child',
      data() {
        return {
          arr: [0, 1, 2, 3, 4],
          obj: {
            name: '白粉花',
            hobby: '白梅梅'
          }
        }
      }
    };

    const parent = {
      template: "#parent",
      components: {
        child
      }
    };

    Vue.component('parent', parent);
    const app = new Vue({
      el: '#app'
    })
  </script>
</body>

</html>